package com.cykj.pos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cykj.pos.domain.BizDayStatistics;
import com.cykj.pos.mapper.BizDayStatisticsMapper;
import com.cykj.pos.service.IBizDayStatisticsService;
import com.cykj.pos.service.IBizMicroInfoService;
import com.cykj.pos.util.LoginUserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * statisticsService业务层处理
 *
 * @author weijianbo
 * @date 2024-05-05
 */
@Service
public class BizDayStatisticsServiceImpl extends ServiceImpl<BizDayStatisticsMapper, BizDayStatistics> implements IBizDayStatisticsService {



    @Override
    public List<BizDayStatistics> queryList(BizDayStatistics bizDayStatistics) {
        LambdaQueryWrapper<BizDayStatistics> lqw = Wrappers.lambdaQuery();

        if (StringUtils.isNotBlank(bizDayStatistics.getVar2())){
            lqw.like(BizDayStatistics::getVar2 ,bizDayStatistics.getVar2());
        }
        if (StringUtils.isNotBlank(bizDayStatistics.getUserName())){
            lqw.like(BizDayStatistics::getUserName ,bizDayStatistics.getUserName());
        }
        Map<String, Object> params = bizDayStatistics.getParams();
        if (params.get("beginWalletTime") != null && params.get("endWalletTime") != null) {
            lqw.between(BizDayStatistics::getWalletTime ,params.get("beginWalletTime"),params.get("endWalletTime"));
        }else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar rightNowToday = Calendar.getInstance();
            rightNowToday.setTime(new Date());
            rightNowToday.add(Calendar.DAY_OF_MONTH, -0);
            Date dt2 = rightNowToday.getTime();
            String today = sdf.format(dt2);
            lqw.between(BizDayStatistics::getWalletTime ,today,today);
        }
        return this.list(lqw);
    }
}
